import React from 'react';
import Client from './Client';
const Login=()=>{
    const [state,setState]=React.useState({username:"mahongquan",password:"mhq730208[]",getScada_data:null,login_data:null,res:null});
    console.log(state);
    return(
    <div>
	<div className="signHeader">
		{/*<span id ="companyName">北京汉升动力科技有限公司</span>*/}
	</div>
    <div className="mom" id="backgroud">
        <div className="signinpanel">
            <div className="row">
                <div className="col-sm-8">
                </div>
                <div className="col-sm-4">
                    <form id="loginForm" method="post" >
                        <p className="signTitle">欢迎登录</p>
                        <p id="error-msg" className="error-msg"></p>
                        <input name="username" value={state.username} onChange={(e)=>{
                            setState((state)=>({...state,username:e.target.value}))
                        }}type="text" className="form-control uname" placeholder="用户名" />
                        <input name="password" value={state.password} onChange={(e)=>{
                            setState((state)=>({...state,password:e.target.value}))
                        }} type="text" className="form-control m-b" placeholder="密码" />
                        <input name="grant_type" type="hidden"  value="password"  />
                        <input name="scope" type="hidden"  value="select" />
                        <input name="client_id" type="hidden" value="client_2"  />
                        <input name="client_secret" type="hidden" value="123456"  />
                        <button className="btn btn-success btn-block" type="button" onClick={()=>{
                            let data={};
                            data.username=state.username
                            data.password=state.password
                            // data.type="2"
                            // data.captcha=""
                            console.log("data input")
                            console.log(data)
                            // data.checkKey="1686279246495"
                            Client.post("/hanson-lcdp/sys/login",data,(data)=>{
                                setState((state)=>({...state,login_data:data}))
                                console.log("ok");
                                console.log(data);
                            },(e)=>{
                                console.log("error");
                                console.log(e);
                            })
                        }}>登录</button>
                        <button className="btn btn-success btn-block" type="button" onClick={()=>{
                            let data={projectId: 'n7hnngimnxalqi2ih8euj59z3upscog1'}
                            Client.post("/hanson-lcdp/oapi/ncstest/test/body1",data,(data)=>{
                                // setState((state)=>({...state,res:data}))
                                console.log(data);
                                console.log("ok");
                                console.log(data);
                            },(e)=>{
                                console.log("error");
                                console.log(e);
                            })
                            // let data={projectId: 'n7hnngimnxalqi2ih8euj59z3upscog1'}
                            // Client.get("/module/getAllModuleTreeUseByRoleIds",data,(data)=>{
                            //     setState((state)=>({...state,res:data}))
                            //     console.log("ok");
                            //     console.log(data);
                            // },(e)=>{
                            //     console.log("error");
                            //     console.log(e);
                            // })
                            // let data={};
                            // data.interfaceId="oapi:2553a21d82b54891a4f1426dcdf4e99f"
                            // Client.post("/hanson-lcdp/oapi/scada/getAllScadaProtocol",data,(data)=>{
                            //     setState((state)=>({...state,getScada_data:data}))
                            //     console.log("ok");
                            //     console.log(data);
                            // },(e)=>{
                            //     console.log("error");
                            //     console.log(e);
                            // })
                        }}>ncstest/test/body1</button>
                    </form>
                </div>

            </div>
        </div>
    </div>
    </div>);
}
export default  Login;

// var form = $('#loginForm');
//         var falg = false;
//         form.find(".form-control").each(function(){
//           if($h.isblank($(this).val())){
//             falg = true;
//              $h.login.showError($(this).attr("placeholder")+"不能为空！");
//              return false;
//           }
//         });
//         if(falg) return;

//         this.post($h.ctx + "oauth/token",form.serialize(),function(data){
//           sessionStorage.setItem("access_token", data.access_token);
//           sessionStorage.setItem("lims_access_token", data.access_token);
//           sessionStorage.setItem("checkUserId", "");
//           location.href ="index.jsp"
//         })